home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / MSDOS.H < prev    next >
C/C++ Source or Header  |  1992-05-05  |  12KB  |  531 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/dos386/microcode/RCS/msdos.h,v 1.1 1992/05/05 06:55:13 jinx Exp $
  4.  
  5. Copyright (c) 1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Unix system include file */
  36.  
  37. #ifndef SCM_DOS_H
  38. #define SCM_DOS_H
  39.  
  40. #define SYSTEM_NAME "dos"
  41. #define SYSTEM_VARIANT "MS-DOS"
  42.  
  43. #include <sys/types.h>
  44. #include <sys/times.h>
  45. #include <dos.h>
  46. #include <io.h>
  47. #include <conio.h>
  48. #include <sys/stat.h>
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <direct.h>
  52. #include <signal.h>
  53. #include <errno.h>
  54. /* We fake these for console I/O in DOS */
  55. #ifndef ESTALE
  56. #define ESTALE        1997
  57. #endif
  58. #ifndef ERRNO_NONBLOCK
  59. #define ERRNO_NONBLOCK    1998
  60. #endif
  61. #ifndef EINTR
  62. #define EINTR        1999
  63. #endif
  64.  
  65. #include "oscond.h"
  66. #include "ansidecl.h"
  67. #include "posixtype.h"
  68.  
  69. #include "intext.h"
  70. #include "dstack.h"
  71. #include "osscheme.h"
  72. #include "dossys.h"
  73.  
  74. enum syscall_names
  75. {
  76.   syscall_accept,
  77.   syscall_bind,
  78.   syscall_chdir,
  79.   syscall_chmod,
  80.   syscall_close,
  81.   syscall_connect,
  82.   syscall_fcntl_GETFL,
  83.   syscall_fcntl_SETFL,
  84.   syscall_fork,
  85.   syscall_fstat,
  86.   syscall_ftruncate,
  87.   syscall_getcwd,
  88.   syscall_gethostname,
  89.   syscall_gettimeofday,
  90.   syscall_ioctl_TIOCGPGRP,
  91.   syscall_ioctl_TIOCSIGSEND,
  92.   syscall_kill,
  93.   syscall_link,
  94.   syscall_listen,
  95.   syscall_localtime,
  96.   syscall_lseek,
  97.   syscall_lstat,    
  98.   syscall_malloc,
  99.   syscall_mkdir,
  100.   syscall_open,
  101.   syscall_opendir,
  102.   syscall_pause,
  103.   syscall_pipe,
  104.   syscall_read,
  105.   syscall_readlink,
  106.   syscall_realloc,
  107.   syscall_rename,
  108.   syscall_select,
  109.   syscall_setitimer,
  110.   syscall_setpgid,
  111.   syscall_sighold,
  112.   syscall_sigprocmask,
  113.   syscall_sigsuspend,
  114.   syscall_sleep,
  115.   syscall_socket,
  116.   syscall_symlink,
  117.   syscall_tcdrain,
  118.   syscall_tcflush,
  119.   syscall_tcgetpgrp,
  120.   syscall_tcsetpgrp,
  121.   syscall_terminal_get_state,
  122.   syscall_terminal_set_state,
  123.   syscall_time,
  124.   syscall_times,
  125.   syscall_unlink,
  126.   syscall_utime,
  127.   syscall_vfork,
  128.   syscall_write
  129. };
  130.  
  131. enum syserr_names
  132. {
  133.   syserr_unknown,
  134.   syserr_arg_list_too_long,
  135.   syserr_bad_address,
  136.   syserr_bad_file_descriptor,
  137.   syserr_broken_pipe,
  138.   syserr_directory_not_empty,
  139.   syserr_domain_error,
  140.   syserr_exec_format_error,
  141.   syserr_file_exists,
  142.   syserr_file_too_large,
  143.   syserr_filename_too_long,
  144.   syserr_function_not_implemented,
  145.   syserr_improper_link,
  146.   syserr_inappropriate_io_control_operation,
  147.   syserr_interrupted_function_call,
  148.   syserr_invalid_argument,
  149.   syserr_invalid_seek,
  150.   syserr_io_error,
  151.   syserr_is_a_directory,
  152.   syserr_no_child_processes,
  153.   syserr_no_locks_available,
  154.   syserr_no_space_left_on_device,
  155.   syserr_no_such_device,
  156.   syserr_no_such_device_or_address,
  157.   syserr_no_such_file_or_directory,
  158.   syserr_no_such_process,
  159.   syserr_not_a_directory,
  160.   syserr_not_enough_space,
  161.   syserr_operation_not_permitted,
  162.   syserr_permission_denied,
  163.   syserr_read_only_file_system,
  164.   syserr_resource_busy,
  165.   syserr_resource_deadlock_avoided,
  166.   syserr_resource_temporarily_unavailable,
  167.   syserr_result_too_large,
  168.   syserr_too_many_links,
  169.   syserr_too_many_open_files,
  170.   syserr_too_many_open_files_in_system
  171. };
  172.  
  173. extern void EXFUN (error_system_call, (int code, enum syscall_names name));
  174.  
  175.  
  176. #include <limits.h>
  177. #include <time.h>
  178. #include <termio.h>
  179.  
  180. #define HAVE_MKDIR
  181. #define HAVE_RMDIR
  182. #define HAVE_GETCWD
  183.  
  184. /* #define HAVE_DUP2 */
  185. /* #define HAVE_FCNTL */
  186. #define VOID_SIGNAL_HANDLERS
  187.  
  188. #include <sys/dir.h>
  189.  
  190. typedef void Tsignal_handler_result;
  191. #define SIGNAL_HANDLER_RETURN() return
  192.  
  193. typedef Tsignal_handler_result (*Tsignal_handler) ();
  194.  
  195. #ifndef SIG_ERR
  196. #define SIG_ERR ((Tsignal_handler) (-1))
  197. #endif
  198.  
  199. #if !defined(SIGCHLD) && defined(SIGCLD)
  200. #define SIGCHLD SIGCLD
  201. #endif
  202. #if !defined(SIGABRT) && defined(SIGIOT)
  203. #define SIGABRT SIGIOT
  204. #endif
  205.  
  206. /* Crufty, but it will work here. */
  207. #ifndef ENOSYS
  208. #define ENOSYS 0
  209. #endif
  210.  
  211. #ifdef UNION_WAIT_STATUS
  212.  
  213. typedef union wait wait_status_t;
  214.  
  215. #ifndef WEXITSTATUS
  216. #define WEXITSTATUS(_X) ((_X) . w_retcode)
  217. #endif
  218.  
  219. #ifndef WTERMSIG
  220. #define WTERMSIG(_X) ((_X) . w_termsig)
  221. #endif
  222.  
  223. #ifndef WSTOPSIG
  224. #define WSTOPSIG(_X) ((_X) . w_stopsig)
  225. #endif
  226.  
  227. #else /* not UNION_WAIT_STATUS */
  228.  
  229. typedef int wait_status_t;
  230.  
  231. #ifndef WIFEXITED
  232. #define WIFEXITED(_X) (((_X) & 0377) == 0)
  233. #endif
  234.  
  235. #ifndef WIFSTOPPED
  236. #define WIFSTOPPED(_X) (((_X) & 0377) == 0177)
  237. #endif
  238.  
  239. #ifndef WIFSIGNALED
  240. #define WIFSIGNALED(_X) ((((_X) & 0377) != 0) && (((_X) & 0377) != 0177))
  241. #endif
  242.  
  243. #ifndef WEXITSTATUS
  244. #define WEXITSTATUS(_X) (((_X) >> 8) & 0377)
  245. #endif
  246.  
  247. #ifndef WTERMSIG
  248. #define WTERMSIG(_X) ((_X) & 0177)
  249. #endif
  250.  
  251. #ifndef WSTOPSIG
  252. #define WSTOPSIG(_X) (((_X) >> 8) & 0377)
  253. #endif
  254.  
  255. #endif /* UNION_WAIT_STATUS */
  256.  
  257. /* Provide null defaults for all the signals we're likely to use so we
  258.    aren't continually testing to see if they're defined. */
  259.  
  260. #ifndef SIGLOST
  261. #define SIGLOST 0
  262. #endif
  263. #ifndef SIGWINCH
  264. #define SIGWINCH 0
  265. #endif
  266. #ifndef SIGURG
  267. #define SIGURG 0
  268. #endif
  269. #ifndef SIGIO
  270. #define SIGIO 0
  271. #endif
  272. #ifndef SIGUSR1
  273. #define SIGUSR1 0
  274. #endif
  275. #ifndef SIGUSR2
  276. #define SIGUSR2 0
  277. #endif
  278. #ifndef SIGVTALRM
  279. #define SIGVTALRM 0
  280. #endif
  281. #ifndef SIGABRT
  282. #define SIGABRT 0
  283. #endif
  284. #ifndef SIGPWR
  285. #define SIGPWR 0
  286. #endif
  287. #ifndef SIGPROF
  288. #define SIGPROF 0
  289. #endif
  290. #ifndef SIGSTOP
  291. #define SIGSTOP 0
  292. #endif
  293. #ifndef SIGTSTP
  294. #define SIGTSTP 0
  295. #endif
  296. #ifndef SIGCONT
  297. #define SIGCONT 0
  298. #endif
  299. #ifndef SIGCHLD
  300. #define SIGCHLD 0
  301. #endif
  302. #ifndef SIGTTIN
  303. #define SIGTTIN 0
  304. #endif
  305. #ifndef SIGTTOU
  306. #define SIGTTOU 0
  307. #endif
  308.  
  309. /* constants for access() */
  310. #ifndef R_OK
  311. #define R_OK 4
  312. #define W_OK 2
  313. #define X_OK 1
  314. #define F_OK 0
  315. #endif
  316.  
  317. #ifndef MAXPATHLEN
  318. #define MAXPATHLEN 128
  319. #endif
  320.  
  321. #ifdef __STDC__
  322. #define ALERT_CHAR '\a'
  323. #define ALERT_STRING "\a"
  324. #else
  325. #define ALERT_CHAR '\007'
  326. #define ALERT_STRING "\007"
  327. #endif
  328.  
  329. #ifndef STDIN_FILENO
  330. #define STDIN_FILENO 0
  331. #define STDOUT_FILENO 1
  332. #define STDERR_FILENO 2
  333. #endif
  334.  
  335. /* constants for open() and fcntl() */
  336. #ifndef O_RDONLY
  337. #define O_RDONLY 0
  338. #define O_WRONLY 1
  339. #define O_RDWR 2
  340. #endif
  341.  
  342. /* mode bit definitions for open(), creat(), and chmod() */
  343. #ifndef S_IRWXU
  344. #define S_IRWXU 0700
  345. #define S_IRWXG 0070
  346. #define S_IRWXO 0007
  347. #endif
  348.  
  349. #ifndef S_IRUSR
  350. #define S_IRUSR 0400
  351. #define S_IWUSR 0200
  352. #define S_IXUSR 0100
  353. #define S_IRGRP 0040
  354. #define S_IWGRP 0020
  355. #define S_IXGRP 0010
  356. #define S_IROTH 0004
  357. #define S_IWOTH 0002
  358. #define S_IXOTH 0001
  359. #endif
  360.  
  361. #define MODE_REG (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
  362. #define MODE_DIR (MODE_REG | S_IXUSR | S_IXGRP | S_IXOTH)
  363.  
  364. /* constants for lseek() */
  365. #ifndef SEEK_SET
  366. #define SEEK_SET 0
  367. #define SEEK_CUR 1
  368. #define SEEK_END 2
  369. #endif
  370.  
  371. #ifndef DECL_GETLOGIN
  372. extern char * EXFUN (getlogin, (void));
  373. #endif
  374.  
  375. #define DOS_abort abort
  376. #define DOS_access access
  377. #define DOS_alarm alarm
  378. #define DOS_chdir chdir
  379. #define DOS_chmod chmod
  380. #define DOS_close close
  381. #define DOS_ctime ctime
  382. #define DOS_dup dup
  383. #define DOS_free free
  384. #define DOS_fstat fstat
  385. #define DOS_getcwd getcwd
  386. #define DOS_getenv getenv
  387. #define DOS_getegid getegid
  388. #define DOS_geteuid geteuid
  389. #define DOS_getgrgid getgrgid
  390. #define DOS_gethostname gethostname
  391. #define DOS_getlogin getlogin
  392. #define DOS_getpid getpid
  393. #define DOS_getpwnam getpwnam
  394. #define DOS_getpwuid getpwuid
  395. #define DOS_ioctl ioctl
  396. #define DOS_link link
  397. #define DOS_localtime localtime
  398. #define DOS_lseek lseek
  399. #define DOS_malloc malloc
  400. #define DOS_mknod mknod
  401. #define DOS_pause pause
  402. #define DOS_pipe pipe
  403. #define DOS_read read
  404. #define DOS_realloc realloc
  405. #define DOS_signal signal
  406. #define DOS_sleep sleep
  407. #define DOS_stat stat
  408. #define DOS_system system
  409. #define DOS_time time
  410. #define DOS_unlink unlink
  411. #define DOS_write write
  412. #define DOS_wait wait
  413.  
  414. extern PTR EXFUN (malloc, (unsigned int size));
  415. extern PTR EXFUN (realloc, (PTR ptr, unsigned int size));
  416. extern int EXFUN (gethostname, (char * name, unsigned int size));
  417.  
  418. #ifdef HAVE_FCNTL
  419. #define DOS_fcntl fcntl
  420. #endif
  421.  
  422. #ifdef HAVE_TRUNCATE
  423. #define DOS_ftruncate ftruncate
  424. #define DOS_truncate truncate
  425. #endif
  426.  
  427. #ifdef HAVE_VFORK
  428. #define DOS_vfork vfork
  429. #else
  430. #define DOS_vfork fork
  431. #endif
  432.  
  433. #ifdef HAVE_SYMBOLIC_LINKS
  434. #define DOS_lstat lstat
  435. #define DOS_readlink readlink
  436. #define DOS_symlink symlink
  437. #else
  438. #define DOS_lstat stat
  439. #endif
  440.  
  441. extern void EXFUN (DOS_prim_check_errno, (enum syscall_names name));
  442.  
  443. #define STD_VOID_SYSTEM_CALL(name, expression)                \
  444. {                                    \
  445.   while ((expression) < 0)                        \
  446.       error_system_call (errno, (name));                \
  447. }
  448.  
  449. #define STD_UINT_SYSTEM_CALL(name, result, expression)            \
  450. {                                    \
  451.   while (((result) = (expression)) < 0)                    \
  452.       error_system_call (errno, (name));                \
  453. }
  454.  
  455. #define STD_PTR_SYSTEM_CALL(name, result, expression)            \
  456. {                                    \
  457.   while (((result) = (expression)) == 0)                \
  458.       error_system_call (errno, (name));                \
  459. }
  460.  
  461. #ifdef HAVE_GETTIMEOFDAY
  462. #define DOS_gettimeofday gettimeofday
  463. #endif
  464. #ifdef HAVE_ITIMER
  465. #define DOS_setitimer setitimer
  466. #endif
  467. #ifdef HAVE_RMDIR
  468. #define DOS_rmdir rmdir
  469. #endif
  470. #ifdef HAVE_TIMES
  471. #define DOS_times times
  472. #endif
  473.  
  474. #ifdef HAVE_DUMB_OPEN
  475. extern int EXFUN (DOS_open, (CONST char * name, int oflag, mode_t mode));
  476. #else
  477. #define DOS_open open
  478. #endif
  479.  
  480. #ifdef HAVE_GETCWD
  481. #define DOS_getcwd getcwd
  482. #else
  483. #define EMULATE_GETCWD
  484. #define HAVE_GETCWD
  485. extern char * EXFUN (DOS_getcwd, (char * buffer, size_t length));
  486. #endif
  487.  
  488. #ifdef HAVE_MKDIR
  489. #define DOS_mkdir mkdir
  490. #else
  491. #define EMULATE_MKDIR
  492. #define HAVE_MKDIR
  493. extern int EXFUN (DOS_mkdir, (CONST char * name, mode_t mode));
  494. #endif
  495.  
  496. #ifdef HAVE_RENAME
  497. #define DOS_rename rename
  498. #else
  499. #define DOS_rename dos_rename_file
  500.  
  501. #ifdef HAVE_WAITPID
  502. #define DOS_waitpid waitpid
  503. #else /* not HAVE_WAITPID */
  504. #ifdef HAVE_WAIT3
  505. #define EMULATE_WAITPID
  506. #define HAVE_WAITPID
  507. extern int EXFUN
  508.   (DOS_waitpid, (pid_t pid, wait_status_t * stat_loc, int options));
  509. #endif /* HAVE_WAIT3 */
  510. #endif /* HAVE_WAITPID */
  511.  
  512. #ifndef WUNTRACED
  513. #define WUNTRACED 0
  514. #endif
  515.  
  516. #ifdef HAVE_SELECT
  517. #define DOS_select select
  518. #endif /* HAVE_SELECT */
  519.  
  520. #ifdef _NFILE
  521. #define DOS_SC_OPEN_MAX() _NFILE
  522. #else
  523. #define DOS_SC_OPEN_MAX() 16
  524. #endif
  525.  
  526. /* Doesn't really go anywhere */
  527. #define INTERRUPT_CHAIN_NEXT    0
  528. #define INTERRUPT_RETURN    1
  529.  
  530. extern void EXFUN (console_write_string, (void * string));
  531.